import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:my_app/pages/user_card.dart';
import '../pages/login.dart';
import '../conponate/user_info.dart';
import 'bottom_navigator.dart';

class DrawLayout extends StatefulWidget {
  const DrawLayout({Key? key}) : super(key: key);

  @override
  _DrawLayoutState createState() => _DrawLayoutState();
}

class _DrawLayoutState extends State<DrawLayout> {

  String userName = UserInfo.userName;
  int _index = 2;

  @override
  Widget build(BuildContext context) {
    print(userName);
    return Drawer(
        child: ListView(
            padding: EdgeInsets.all(0.0),
            children: <Widget>[
              UserAccountsDrawerHeader(
                accountName: Text(userName,style:TextStyle(fontSize: 20),),
                accountEmail: Text(""),
                currentAccountPicture: FittedBox(
                  fit: BoxFit.cover,
                  child: CircleAvatar(
                    child: Icon(
                      Icons.person,
                      color: Colors.white,
                    ),
                    backgroundColor: Colors.white38,
                    radius: 20,
                  ),
                ),
                decoration: BoxDecoration(
                    color: Colors.blueGrey
                ),
              ),
              GestureDetector(
                child:Container(
                  height: 50,
                  child: Flex(
                    direction: Axis.horizontal,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [Expanded(flex:1,child: Icon(Icons.person,color: Colors.blueGrey,),),
                      Expanded(flex:4,child: Text("用户",
                        style: TextStyle(color: Colors.blueGrey,
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                        ),),),],)
                  ),
              onTap: ()async {
                print(UserInfo.userName);
                if(UserInfo.userName != "未登录"){
                  Navigator.of(context).pop();
                  BottomNavigatorBarDemo();
                } else {
                  String name = await Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) {
                        return LoginNameAndPassword();
                      }
                    )
                  );
                  this.userName = name;
                };},
              ),

              GestureDetector(
                child:Container(
                    height: 50,
                    child: Flex(
                      direction: Axis.horizontal,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [Expanded(flex:1,child: Icon(Icons.exit_to_app,color: Colors.blueGrey,),),
                        Expanded(flex:4,child: Text("退出",
                          style: TextStyle(color: Colors.blueGrey,
                            fontSize: 20,
                            fontWeight: FontWeight.bold,
                          ),),),],)
                ),
                onTap:() {
                  UserInfo.userName = "未登录";
                },
              ),
            ]
        )
    );
  }
}


